package com.gill.exp.controller;

import com.gill.exp.common.HttpResult;
import com.gill.exp.pojo.dto.UserDTO;
import com.gill.exp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import sun.net.ftp.FtpProtocolException;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.io.IOException;

/**
 * @author gill
 */
@RestController
@Validated
public class UserController {

//    ==============================================参数校验相关 ==============================================

    /**
     * 方法参数为实体校验
     */
    @PostMapping("/test1")
    public ResponseEntity test1(@Valid @RequestBody UserDTO userDTO){

        return ResponseEntity.ok(userDTO);
    }

    /**
     * 方法参数校验
     */
    @GetMapping("/test2")
    public ResponseEntity test2(@NotNull(message ="column1不能为空")
                                    @RequestParam("column1") String column1) {
        UserDTO userDTO = new UserDTO();
        userDTO.setColumn1(column1);
        return ResponseEntity.ok(userDTO);
    }


//    ==============================================controller层设计相关 ==============================================

    @Autowired
    UserService userService;

    @GetMapping("/test3")
    public HttpResult test3(){
        UserDTO userDTO = UserDTO.convertFromDO(userService.getUser());
        return HttpResult.ok(userDTO);
    }
}